package com.leetcode.p300;

import java.util.Arrays;

public class Test322 {

    public int coinChange(int[] coins, int amount) {
        int count = amount + 1;
        int[] dp = new int[count];
        Arrays.fill(dp, amount + 1);
        dp[0] = 0;

        for (int i = 1; i <= amount; i++) {
            for (int j = 0; j < coins.length; j++) {
                if (coins[j] <= i)
                    dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1);
            }
        }

        return dp[amount] > amount ? -1 : dp[amount];
    }

    public static void main(String[] args) {
        Test322 test = new Test322();
        System.out.println(test.coinChange(new int[]{1, 2, 5, 7, 10}, 14));
//        System.out.println(test.coinChange(new int[]{1, 2, 5, 7, 10}, 1));
    }
}
